package com.glb.gilibuy.service.impl;

import com.github.pagehelper.PageInfo;
import com.glb.gilibuy.dao.CyclePicDao;
import com.glb.gilibuy.entity.*;
import com.glb.gilibuy.service.CyclePicService;
import com.glb.gilibuy.util.BeanUtil;
import com.glb.gilibuy.web.vo.CyclePicVO;
import com.glb.gilibuy.web.vo.UserReceiveAddressVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/6 9:14
 */
@Service
public class CyclePicServiceImpl implements CyclePicService {
    @Autowired
    private CyclePicDao cyclePicDao;

    @Override
    public CyclePic selectCyclePicByCyclePicId(String picId) {
        if (!"".equals(picId)) {
            CyclePicExample cyclePicExample = new CyclePicExample();
            cyclePicExample.or().andCyclePicEqualTo(picId).andIsDeletedEqualTo(0);
            List<CyclePic> cyclePicList = cyclePicDao.selectByExample(cyclePicExample);
            if (cyclePicList.isEmpty()) {
                return null;
            }
            return cyclePicList.get(0);
        }
        return null;
    }

    @Override
    public List<CyclePic> selectAllCyclePics() {
        CyclePicExample cyclePicExample = new CyclePicExample();
        cyclePicExample.setOrderByClause("cycle_pic_sequence desc , id desc");
        cyclePicExample.or().andIsDeletedEqualTo(0);
        List<CyclePic> cyclePicList = cyclePicDao.selectByExample(cyclePicExample);
        return cyclePicList;
    }

    @Override
    public PageInfo findAllCyclePics() {
        List<CyclePic> cyclePicList = selectAllCyclePics();
        if (cyclePicList.isEmpty()) {
            return null;
        }
        PageInfo pageInfo = new PageInfo(cyclePicList);
        List<CyclePicVO> cyclePicVOList = BeanUtil.copyList(cyclePicList, CyclePicVO.class);
        pageInfo.setList(cyclePicVOList);
        return pageInfo;
    }

    @Override
    public int addCyclePic(CyclePic cyclePic) {
        if (cyclePic == null) {
            return 0;
        }

        //后台不校参

        if (cyclePicDao.insertSelective(cyclePic) > 0) {
            return 1;
        }
        return 0;
    }

}
